<?php

namespace App\Providers;

use App\Models\Topic;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Log;
use Illuminate\Support\ServiceProvider;
use Illuminate\Support\Facades\Schema;
class AppServiceProvider extends ServiceProvider
{
    /**
     * Bootstrap any application services.
     *
     * @return void
     */
    public function boot()
    {
        Schema::defaultStringLength(191);
        $topics = Topic::get();
        \View::composer('layout.sidebar', function ($view) use($topics){
            $view->with('topics',$topics);
        });

        \View::composer('layout.nav', function ($view){
            $visitor = (object)['id'=>'-1','nickname'=>'游客'];
            $me = \Auth::check() ? \Auth::user():  $visitor ;
            $view->with('me',$me);
        });

        \View::composer('backend.layout.header',function($view){
            $view->with('admin',\Auth::guard('admin')->user());
        });

        \View::composer('backend.layout.sidebar',function($view){
            $permissions = \Auth::guard('admin')->user()->permissions();
            $view->with('admin',\Auth::guard('admin')->user())->with('permissions',$permissions);
        });


    }

    /**
     * Register any application services.
     *
     * @return void
     */
    public function register()
    {
        //
    }
}
